package com.berchen.test;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

public class ThreadPoolDemo1 {
    public static void main(String[] args)  {
        try {
            System.out.println(test());
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("is ok");

    }
    public static int test() throws ExecutionException, InterruptedException {
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(3, 6, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(3));

        AtomicInteger a= new AtomicInteger();
        CompletableFuture future1=CompletableFuture.runAsync(()->{
            a.addAndGet(10);
        });
        CompletableFuture future2=CompletableFuture.runAsync(()->{
            a.addAndGet(20);
            int i=1/0;
        });
        CompletableFuture.allOf(future1,future2).get();
        System.out.println("ok");
        return a.get();
    }
}
